// pages/WeUI/WeUI.js
var sliderWidth = 96; // 需要设置slider的宽度，用于计算中间位置
Page({
  data: {
    tabs: ['热销商品',  '计算器'], // 标签页标题数组
    activeIndex: 0, // 当前选中的标签页索引
    sliderOffset: 0, // 指示条的平移距离
    sliderLeft: 0, // 指示条的left值
    contents: [{
        title: '苹果',
        article: '一斤八块五。'
      },
      {
        title: '香蕉',
        article: '18厘米。'
      },
      {
        title: '菠萝',
        article: '一天18公斤。'
      },
      {
        title: '西瓜',
        article: '好大一个。'
      },
      {
        title: '芒果',
        article: '上过大学的芒果。'
      },
      {
        title: '榴莲',
        article: '粑粑。'
      }
    ],
    grids: [
      '1', '2', '3', '4', '5', '6', '7', '8', '9','0','+','-','*','/','='
    ]
  },
  onLoad: function() {
    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });
  },
  tabClick: function (e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id
    });
  }
})